package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.happy.cat.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import com.happy.cat.project.system.domain.SocialVoiceRoom;
import com.happy.cat.project.system.service.ISocialVoiceRoomService;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.common.utils.poi.ExcelUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.happy.cat.framework.web.page.TableDataInfo;

/**
 * 语音聊天室房间Controller
 *
 * @author verne
 * @date 2020-08-29
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/socialVoiceRoom" )
@Api("语音聊天室房间 API")
public class SocialVoiceRoomController extends BaseController {

    private final ISocialVoiceRoomService iSocialVoiceRoomService;

    /**
     * 查询语音聊天室房间列表
     */
    @ApiOperation(value = "查询语音聊天室房间列表",notes = "查询语音聊天室房间列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:socialVoiceRoom:list')")
    @GetMapping("/list")
    public TableDataInfo list(SocialVoiceRoom socialVoiceRoom)
    {
        startPage();
        LambdaQueryWrapper<SocialVoiceRoom> lqw = new LambdaQueryWrapper<SocialVoiceRoom>();
        if (StringUtils.isNotBlank(socialVoiceRoom.getRoomId())){
            lqw.eq(SocialVoiceRoom::getRoomId ,socialVoiceRoom.getRoomId());
        }
        if (StringUtils.isNotBlank(socialVoiceRoom.getName())){
            lqw.like(SocialVoiceRoom::getName ,socialVoiceRoom.getName());
        }
        if (StringUtils.isNotBlank(socialVoiceRoom.getCreator())){
            lqw.eq(SocialVoiceRoom::getCreator ,socialVoiceRoom.getCreator());
        }
        if (StringUtils.isNotBlank(socialVoiceRoom.getManager())){
            lqw.eq(SocialVoiceRoom::getManager ,socialVoiceRoom.getManager());
        }
        if (StringUtils.isNotBlank(socialVoiceRoom.getThumbnail())){
            lqw.eq(SocialVoiceRoom::getThumbnail ,socialVoiceRoom.getThumbnail());
        }
        if (StringUtils.isNotBlank(socialVoiceRoom.getValid())){
            lqw.eq(SocialVoiceRoom::getValid ,socialVoiceRoom.getValid());
        }
        if (StringUtils.isNotBlank(socialVoiceRoom.getVisible())){
            lqw.eq(SocialVoiceRoom::getVisible ,socialVoiceRoom.getVisible());
        }
        if (StringUtils.isNotBlank(socialVoiceRoom.getHot())){
            lqw.eq(SocialVoiceRoom::getHot ,socialVoiceRoom.getHot());
        }
        List<SocialVoiceRoom> list = iSocialVoiceRoomService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出语音聊天室房间列表
     */
    @ApiOperation(value = "导出语音聊天室房间列表",notes = "导出语音聊天室房间列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:socialVoiceRoom:export')" )
    @Log(title = "语音聊天室房间" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(SocialVoiceRoom socialVoiceRoom) {
        LambdaQueryWrapper<SocialVoiceRoom> lqw = new LambdaQueryWrapper<SocialVoiceRoom>(socialVoiceRoom);
        List<SocialVoiceRoom> list = iSocialVoiceRoomService.list(lqw);
        ExcelUtil<SocialVoiceRoom> util = new ExcelUtil<SocialVoiceRoom>(SocialVoiceRoom. class);
        return util.exportExcel(list, "socialVoiceRoom" );
    }

    /**
     * 获取语音聊天室房间详细信息
     */
    @ApiOperation(value = "获取语音聊天室房间详细信息",notes = "获取语音聊天室房间详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:socialVoiceRoom:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iSocialVoiceRoomService.getById(id));
    }

    /**
     * 新增语音聊天室房间
     */
    @ApiOperation(value = "新增语音聊天室房间",notes = "新增语音聊天室房间",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:socialVoiceRoom:add')" )
    @Log(title = "语音聊天室房间" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SocialVoiceRoom socialVoiceRoom) {
        return toAjax(iSocialVoiceRoomService.save(socialVoiceRoom) ? 1 : 0);
    }

    /**
     * 修改语音聊天室房间
     */
    @ApiOperation(value = "修改语音聊天室房间",notes = "修改语音聊天室房间",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:socialVoiceRoom:edit')" )
    @Log(title = "语音聊天室房间" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SocialVoiceRoom socialVoiceRoom) {
        return toAjax(iSocialVoiceRoomService.updateById(socialVoiceRoom) ? 1 : 0);
    }

    /**
     * 删除语音聊天室房间
     */
    @ApiOperation(value = "删除语音聊天室房间",notes = "删除语音聊天室房间",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:socialVoiceRoom:remove')" )
    @Log(title = "语音聊天室房间" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iSocialVoiceRoomService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
